package com.um.jdy.common.charge.service.impl;


import cn.hutool.json.JSONUtil;
import com.um.jdy.common.charge.enums.OrderAction;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.um.springboot.starter.orm.service.BaseEntityServiceImpl;
import com.um.jdy.common.charge.service.DataLogService;
import com.um.jdy.common.charge.dao.DataLogDao;
import com.um.jdy.common.charge.entity.po.DataLog;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 服务实现类：充电实时数据日志表
 */
@Service
@Slf4j
public class DataLogServiceImpl extends BaseEntityServiceImpl<DataLogDao,DataLog>  implements DataLogService{

    /**
     * 保存记录订单操作日志
     * @param orderId 订单ID
     * @param action 操作类型
     * @param time 时间
     * @param data 其他数据
     * @param remark 描述
     */
    public void saveChargeData(String comId, String orderId, OrderAction.EV action, Date time, Object data, String remark){
        DataLog dataLog = new DataLog();
        dataLog.setComId(comId);
        dataLog.setChargeOrderId(orderId);
        dataLog.setAction(action.name());
        dataLog.setActionZh(action.getValue());
        dataLog.setCreateTime(time);
        dataLog.setJsonData(JSONUtil.toJsonStr(data));
        dataLog.setRemark(remark);
        this.saveRow(dataLog);
    }
}
